package 动态规划;

/**
 * @author tmh
 * @date 2024/12/12 20:02
 * @description
 */
public class T198打家劫舍 {
    public int rob(int[] nums) {
        int[] dp = new int[nums.length + 1];
        dp[0] = 0;
        dp[1] = nums[0];
        for (int n = 2; n <= nums.length; n++) {
            dp[n] = Math.max(nums[n - 1] + dp[n - 2], dp[n - 1]);
        }
        return dp[nums.length];
    }

}
